﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ScreenMonitor.Common;
using System.Net;
using System.Net.Sockets;
using ScreenMonitor.ServerLib;
using ScreenMonitor.Common.Objects;

namespace ServerUI
{
    public partial class SendMessageWnd : Form
    {
        public SendMessageWnd()
        {
            InitializeComponent();
        }

        public void ReSetList()
        {
            tviewList.Nodes.Clear();
            foreach (ScreenViewerMini m in Program.ClientManager.flowLayoutPanel1.Controls)
            {
                if (m.Client.State == ClientState.Connected)
                {
                    TreeNode tnode = new TreeNode();
                    tnode.Text = m.Client.InfoStr;
                    tnode.Tag = m.Client;
                    tnode.Checked = true;
                    tviewList.Nodes.Add(tnode);
                }
            }
        }

        private void SendMessageWnd_Load(object sender, EventArgs e)
        {
            ReSetList();
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            foreach (TreeNode tnode in tviewList.Nodes)
            {
                if (tnode.Checked == true)
                {
                    ((ClientObject)tnode.Tag).SendMsg(this.txtHead.Text,this.txtMsg.Text);
                }
            }
            MessageBox.Show("发送完毕！");
        }

        private void toolSelAll_Click(object sender, EventArgs e)
        {
            foreach (TreeNode t in tviewList.Nodes)
            {
                t.Checked = true;
            }
        }

        private void toolUnSelAll_Click(object sender, EventArgs e)
        {
            foreach (TreeNode t in tviewList.Nodes)
            {
                t.Checked = false;
            }
        }

        private void toolAvAll_Click(object sender, EventArgs e)
        {
            foreach (TreeNode t in tviewList.Nodes)
            {
                t.Checked = !t.Checked;
            }
        }

    }
}
